/**
 * 
 */
package br.com.movelaria.modelo;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Index;

/**
 * @author fabricio
 * 
 */
@Entity
@Table(name = "operacao")
public class Operacao implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5667737609076622647L;
	@Id
	@Column(name = "idOperacao")
	@SequenceGenerator(name = "SEQ_OPERACAO", sequenceName = "SEQ_ID_OPERACAO", allocationSize = 1)
	@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "SEQ_OPERACAO")
	private Integer idOperacao;
	@Index(name = "IDX_NOME_OPERACAO")
	@Column(name = "nome", length = 200, nullable = false)
	private String nome;
	@OneToMany(mappedBy = "idOperacao.operacao")
	private Set<OperacaoPeca> operacaoPeca = new HashSet<OperacaoPeca>();

	public Integer getIdOperacao() {
		return idOperacao;
	}

	public void setIdOperacao(Integer idOperacao) {
		this.idOperacao = idOperacao;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public Set<OperacaoPeca> getOperacaoPeca() {
		return operacaoPeca;
	}

	public void setOperacaoPeca(Set<OperacaoPeca> operacaoPeca) {
		this.operacaoPeca = operacaoPeca;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((idOperacao == null) ? 0 : idOperacao.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Operacao other = (Operacao) obj;
		if (idOperacao == null) {
			if (other.idOperacao != null)
				return false;
		} else if (!idOperacao.equals(other.idOperacao))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return nome;
	}
}
